import Router from "vue-router";
import login from "../views/login/login";
import Layout from "../views/main/Layout";
import index1 from "../views/menu/worker.vue";
import index2 from "../views/menu/customer.vue";
import addquestion from "../views/menu/addquestion.vue";
import showolders from "../views/menu/showolders.vue";
import help from "../views/menu/help.vue";
import Problemhand from "../views/menu/Problemhand.vue";
import checkolder from "../views/menu/checkolder.vue";
import checkproblem from "../views/menu/checkproblem.vue";
import olderStatistical from "../views/menu/olderStatistical.vue";
import menulist from "../views/menu/menulist.vue";
import addUser from "../views/menu/addUser.vue"
import userStatistical from "../views/menu/userStatistical.vue"
import userJurisdiction from "../views/menu/userJurisdiction.vue"
import AcceptedProblem from "../views/menu/AcceptedProblem.vue"
import Notaccepted from "../views/menu/Notaccepted.vue"
import lookrate from "../views/menu/lookrate.vue"
import home from "../charts/statistical.vue"
const router = new Router({
    routes: [
        {
            path: "/",
            name: "login",
            component: login,
        },

        {
            path: "/Layout",
            name: "Layout",
            component: Layout,
            meta: {
                requirAuth: true,
            },
            children: [
                {
                    path: "/checkolder",
                    name: "checkolder",
                    component: checkolder,
                }, {
                    path: "/AcceptedProblem",
                    name: "AcceptedProblem",
                    component: AcceptedProblem

                },{

                    path:"/home",
                    component:home

                },
                {
                    path: "/userJurisdiction",
                    name: "userJurisdiction",
                    component: userJurisdiction
                },
                {
                    path: "/userStatistical",
                    name: "userStatistical",
                    component: userStatistical

                },
                {
                    path: "/lookrate",
                    name: "lookrate",
                    component: lookrate

                },
                {
                    path: "/menulist",
                    name: "menulist",
                    component: menulist

                },

                {
                    path: "/Acceptance",
                    name: "Acceptance",
                    component: checkproblem,
                },
                {
                    path: "/index1",
                    name: "index1",
                    component: index1,
                },
                {
                    path: "/Notaccepted",
                    component: Notaccepted

                },
                {
                    path: "/addUser",
                    name: "addUser",
                    component: addUser,
                },
                {
                    path: "/help",
                    name: "常见问题",
                    component: help,
                },
                {
                    path: "/Problemhand",
                    name: "处理问题",
                    component: Problemhand,
                },
                {
                    path: "/showolders",
                    name: "查看工单",
                    component: showolders,
                },

                {
                    path: "/olderStatistical",
                    name: "olderStatistical",
                    component: olderStatistical,
                },

                {
                    path: "/addques",
                    name: "上诉问题",
                    component: addquestion,
                },
                {
                    path: "/index2",
                    name: "index2",
                    component: index2,
                },
            ],
        },
    ],
    mode: "history",
    base: process.env.BASE_URL,
});

router.beforeEach((to, from, next) => {
    
    let token = localStorage.getItem("Authorization");
  
    let roleId = localStorage.getItem("roleId");

    if (token == null) {
        if (to.path != "/") {
            next({
                path: "/"
            })
        }
        next();
    } else {
        next();
        if (roleId == 1) {
            if (to.path == "/Layout" || to.path == "/") {
                next({
                    path: "/home",
                });
            }
        } else if (roleId == 2) {
            if (to.path == "/Layout" || to.path == "/") {
                next({
                    path: "/checkolder",
                });
            }
        } else if (roleId == 3) {
            if (to.path == "/Layout" || to.path == "/") {
                next({
                    path: "/help",
                });

            }
        }
    }
});

export default router;
